package com.siwei.mes.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.siwei.mes.common.query.PageQuery;
import com.siwei.mes.entity.AppVersion;
import com.siwei.mes.mapper.AppVersionMapper;
import com.siwei.mes.service.AppVersionService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

import static com.siwei.mes.common.exception.handler.MessageHandler.assertTrue;

/**
 * app版本号(AppVersion)表服务实现类
 *
 * @author linzi
 * @since 2024-01-29 22:26:24
 */
@Service
public class AppVersionServiceImpl implements AppVersionService {
    @Resource
    private AppVersionMapper appVersionMapper;

    @Override
    public Long create(AppVersion entity) {
        appVersionMapper.insertSelective(entity);
        return entity.getId();
    }

    @Override
    public void update(AppVersion entity) {
        AppVersion appVersion = appVersionMapper.selectByPrimaryKey(entity.getId());
        assertTrue(appVersion == null, "app版本号信息不存在");
        appVersionMapper.updateByPrimaryKeySelective(entity);
    }

    @Override
    public void delete(Long id) {
        AppVersion appVersion = appVersionMapper.selectByPrimaryKey(id);
        assertTrue(appVersion == null, "app版本号信息不存在");
        appVersionMapper.deleteByPrimaryKey(id);
    }

    @Override
    public PageInfo<AppVersion> getPage(PageQuery<AppVersion, AppVersion> query) {
        AppVersion searchParam = query.getParams();
        return PageHelper.startPage(query.getPageNum(), query.getPageSize())
                .doSelectPageInfo(() -> appVersionMapper.getList(searchParam));
    }

    @Override
    public AppVersion loadById(Long id) {
        return appVersionMapper.loadById(id);
    }

    @Override
    public List<AppVersion> getAll(AppVersion entity) {
        return appVersionMapper.getList(entity);
    }

    @Override
    public AppVersion getVersion(String platform) {
        return appVersionMapper.getVersion(platform);
    }
}
